package com.timothy.junk.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.sina.util.StringUtil;
import com.timothy.junk.R;
import com.timothy.junk.gfund.bean.GFundBeanResult;

import java.util.HashMap;
import java.util.List;

public class GFundAdaptor extends BaseAdapter {
	private Context 					mContext;
	private List<GFundBeanResult> 		listItems;
	private LayoutInflater 				mInflater;

	HashMap<Integer,View> viewMap = new HashMap<Integer,View>();

	static class ViewHolder{
		public TextView fundIndex;
        public TextView fundAName;
        public TextView fundAPrice;
	    public TextView fundBName;
	    public TextView fundBPrice;
	    public TextView fundMName;
	    public TextView fundMValueEstimate;
	    public TextView discount;
	 }

	public GFundAdaptor(Context context, List<GFundBeanResult> data) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context); 
		this.listItems = data;
	}

	
	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;  
        if (convertView == null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.gfund_list_item, null);
            
            holder.fundIndex = (TextView) convertView.findViewById(R.id.fundIndex);
			holder.fundAName = (TextView) convertView.findViewById(R.id.fundAName);
			holder.fundAPrice = (TextView) convertView.findViewById(R.id.fundAPrice);
			holder.fundBName = (TextView) convertView.findViewById(R.id.fundBName);
			holder.fundBPrice = (TextView) convertView.findViewById(R.id.fundBPrice);
			holder.fundMName = (TextView) convertView.findViewById(R.id.fundMName2);
			holder.fundMValueEstimate = (TextView) convertView.findViewById(R.id.fundMValueEstimate);
			holder.discount = (TextView) convertView.findViewById(R.id.discount);
			
            convertView.setTag(holder);  
        }else {  
            holder = (ViewHolder) convertView.getTag();  
        }

        GFundBeanResult bean = listItems.get(position);
        holder.fundIndex.setText(String.valueOf(position+1));
		holder.fundAName.setText(bean.getFundAName());
		holder.fundAPrice.setText(String.valueOf(bean.getFundAPrice()));
		holder.fundBName.setText(bean.getFundBName());
		holder.fundBPrice.setText(String.valueOf(bean.getFundBPrice()));
		holder.fundMName.setText(bean.getFundMName());
		holder.fundMValueEstimate.setText(StringUtil.formatData4Deci(bean.getFundMValueEstimate()));
		holder.discount.setText(StringUtil.formatData2Deci(bean.getDiscount()*100)+"%");

        return convertView; 
        
	}

}
